package com.example.asus.yuejian_10.adapter;


import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.asus.yuejian_10.R;
import com.example.asus.yuejian_10.activity.ActDetail;
import com.example.asus.yuejian_10.bean.ListResult_1;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.asus.yuejian_10.Config.PIC_URL;

/**
 * Created by Administrator on 2017/10/18 0018.
 */

public class ActivityAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<ListResult_1> list;
    private View view;

    public ActivityAdapter(Context context, List<ListResult_1> list){
        this.context=context;
        this.list=list;
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        view= LayoutInflater.from(context).inflate(R.layout.item_activity,parent,false);
        ActivityViewholder viewHolder=new ActivityViewholder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ActivityViewholder activityViewholder=(ActivityViewholder) holder;
        final ListResult_1 actresult =list.get(position);
        final String address=PIC_URL+actresult.getThumb();
        activityViewholder.title.setText("报名人数："+actresult.getActivity_name());
        if (!address.equals("")){
            Picasso.with(context).load(address).into(activityViewholder.pic);
        }
        else {
            activityViewholder.pic.setImageResource(R.drawable.diagonallayout_background);
        }

        activityViewholder.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               Intent intent=new Intent(context, ActDetail.class);
                intent.putExtra("act_id",actresult.getId());
                intent.putExtra("act",actresult);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ActivityViewholder extends RecyclerView.ViewHolder{
        ImageView pic;
        LinearLayout item;
        TextView title;

        public ActivityViewholder(View itemView) {
            super(itemView);
            item=(LinearLayout) itemView.findViewById(R.id.item_act);
            pic=(ImageView) itemView.findViewById(R.id.item_act_pic);
            title=(TextView) itemView.findViewById(R.id.item_act_text);
        }
    }

}
